package com.dmz.wxcp.wecom.wxbusiness.controller;

import com.dmz.wxcp.utils.DataResult;
import com.dmz.wxcp.vo.req.ProductReqVO;
import com.dmz.wxcp.vo.req.StudyArticleReqVO;
import com.dmz.wxcp.vo.resp.PageRespVO;
import com.dmz.wxcp.wecom.wxbusiness.entity.Article;
import com.dmz.wxcp.wecom.wxbusiness.entity.ProductCategory;
import com.dmz.wxcp.wecom.wxbusiness.mapper.StudyArticleMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

@Controller
@Slf4j
@RequestMapping("/study")
public class StudyController {

    @Autowired
    private StudyArticleMapper studyArticleMapper;

    @RequestMapping("/getstudyarticlelist")
    @ResponseBody
    public DataResult studyarticlelist(@RequestParam Map<String,Object> map){
        StudyArticleReqVO vo=new StudyArticleReqVO();

        vo.setArticleTitle((map.get("articletitle").toString()));
        vo.setAuthorName(map.get("authorname").toString());
        vo.setTag(map.get("tag").toString());

        vo.setCurrentPage(new Long(map.get("page").toString()));
        vo.setPageSize(new Long(map.get("limit").toString()));
        vo.setStartNum((vo.getCurrentPage()-1)*vo.getPageSize());

        List<Object> result=studyArticleMapper.getStudyArticleList(vo);
        List<Article> articles=(List<Article>)result.get(0);
        Long count= new Long(((List<Integer>) result.get(1)).get(0));

        PageRespVO<Article> respVO=new PageRespVO<Article>();
        respVO.setRecords(articles);
        respVO.setTotal(count);
        return DataResult.success(respVO);
    }

    @GetMapping("/studyarticlelist")
    public String studyarticleindex(Model model){
        return "studyarticleindex";
    }

}
